package com.peanut.web.controller.admin;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.peanut.model.User;
import com.peanut.service.UserService;
import com.peanut.util.Pagination;
import com.peanut.web.controller.BaseController;
@Controller
@RequestMapping(value = "/admin/user")
public class UserController extends BaseController {
	private UserService userService;
	
	@Autowired
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	@RequestMapping(value = "/manage")
	public ModelAndView showView(ModelAndView mav) {
		
		return mav;
	}
	
	@RequestMapping(value = "/report")
	public ModelAndView showReport(ModelAndView mav) {
		
		return mav;
	}
	
	@RequestMapping(value = "/all")
	@ResponseBody
	public Pagination<User> queryAllUser(Pagination<User> page, HttpServletRequest request) {
		String p1 = request.getParameter("p1");
//		Map<String, Object> record = new HashMap<String, Object>();
//		record.put("rows", userService.queryAllUser(""));
//		record.put("totalRows", 11);
		//page.setPagingRows(userService.queryAllUser(""));
		Map param = new HashMap();
		param.put("sort", page.getSort());
		param.put("dir", page.getDir());
		//page.setPagingRows(userService.queryAllUser(param));
		page.setPagingRows(userService.queryAllUserWithPage(param, page.getStart(), page.getLimit()));
		page.setTotalRows(userService.queryAllUserCount(param));
		//page.setTotalRows((long)165);
		return page;
	}
}
